package com.atguigu.common.service.exception;

import com.atguigu.spzx.model.vo.base.Result;
import com.atguigu.spzx.model.vo.base.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

/**
 * @Author yaya
 * @Create 2024/5/31 18:59
 * Description:
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    // 超出文件最大上限异常处理
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public Result error(MaxUploadSizeExceededException e){
        e.printStackTrace();
        return Result.fail(ResultCodeEnum.ERROR_MAX_UPLOAD_SIZE_EXCEEDED);
    }

    @ExceptionHandler(SpzxException.class)
    public Result error(SpzxException e){
        e.printStackTrace();
        return Result.fail(e.getResultCodeEnum());
    }

    // 全局异常处理最后处理
    @ExceptionHandler(Exception.class)
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail();
    }
}
